package server.service.doctor;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import domain.doctor.Doctor;
import domain.session.Response;

public class DoctorAction {
	
	private DoctorModel doctorModel;
	
	public DoctorAction() {
		doctorModel = new DoctorModel();
	}
	
	public Response getDoctor(final JSONObject requestJson) {
		Integer docId = requestJson.getInt("userId");
		Doctor doc = doctorModel.getDoctor(docId);
		Response response = new Response(true, doc.getJSON());
		return response;
	}
	
	public Response getAllDoctors(final JSONObject requestJson) {
		List<Doctor> doctors = doctorModel.getAllDoctors();
		JSONArray allDoctorsArray = new JSONArray();
		for (Doctor doctor : doctors) {
			allDoctorsArray.put(doctor.getJSON());
		}
		JSONObject responseJson = new JSONObject();
		responseJson.put("doctors", allDoctorsArray);
		Response response = new Response(true, responseJson);
		return response;
	}



}
